//
//  EssentialParameterTableViewCell.m
//  RTUApp
//
//  Created by 陈德军 on 2017/6/28.
//  Copyright © 2017年 陈德军. All rights reserved.
//

#import "EssentialParameterTableViewCell.h"


@interface EssentialParameterTableViewCell()<UITextFieldDelegate>{
    
}

@end

@implementation EssentialParameterTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


+(instancetype)cellWithtableView:(UITableView *)tableview
{
    static NSString *ID = @"cell";
    EssentialParameterTableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:ID];
    if(!cell)
    {
        cell = [[EssentialParameterTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
    
}

//重写布局
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.orderNumberLabel = [UILabel new];
        self.orderNumberLabel.font = [UIFont systemFontOfSize:11];
        self.orderNumberLabel.textAlignment = NSTextAlignmentCenter;
        self.orderNumberLabel.text = @"1";
        self.orderNumberLabel.size = CGSizeMake(50, 44);
        self.orderNumberLabel.left = 20;
        self.orderNumberLabel.centerY = self.contentView.centerY;
        [self.contentView addSubview:self.orderNumberLabel];
        
        self.equipmentNameLabel = [UILabel new];
        self.equipmentNameLabel.textAlignment = NSTextAlignmentCenter;
        self.equipmentNameLabel.numberOfLines = 0;
        self.equipmentNameLabel.text = @"蓝牙设备";
        self.equipmentNameLabel.font = [UIFont systemFontOfSize:11];
        self.equipmentNameLabel.size = CGSizeMake(80, 44);
        self.equipmentNameLabel.left = self.orderNumberLabel.right+5;
        self.equipmentNameLabel.centerY = self.contentView.centerY;
        [self.contentView addSubview:self.equipmentNameLabel];
        
        self.macIDLabel = [UITextField new];
        self.macIDLabel.textAlignment = NSTextAlignmentCenter;
        self.macIDLabel.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        self.macIDLabel.delegate = self;
        self.macIDLabel.textAlignment = NSTextAlignmentCenter;
        self.macIDLabel.font = [UIFont systemFontOfSize:11];
        self.macIDLabel.size = CGSizeMake(130, 44);
        self.macIDLabel.left = self.equipmentNameLabel.right + 5;
        self.macIDLabel.centerY = self.contentView.centerY;
        [self.contentView addSubview:self.macIDLabel];
        
        self.connectBut = [UILabel new];
        self.connectBut.textAlignment = NSTextAlignmentCenter;
        self.connectBut.numberOfLines = 0;
        self.connectBut.font = [UIFont systemFontOfSize:11];
        self.connectBut.size = CGSizeMake(80, 44);
        self.connectBut.centerY = self.contentView.centerY;
        self.connectBut.left = self.macIDLabel.right + 5;
        [self.contentView addSubview:self.connectBut];
    }
    return self;
}

//给cell控件赋值
-(void)setModel:(SearchEquipmentModel *)model{
    self.orderNumberLabel.text = model.num;
    self.equipmentNameLabel.text = model.name;
    self.macIDLabel.text = model.macID;
    self.connectBut.text = model.butTitle;
}


- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (self.delegate && [self.delegate respondsToSelector:@selector(didClickTextField: andID:andName:)]) {
        [self.delegate didClickTextField:textField.text andID:self.orderNumberLabel.text andName:self.equipmentNameLabel.text];
    }
}

@end
